from tortoise.models import Model
from tortoise import fields
from datetime import datetime


class Store(Model):
    """
    库存模型
    """
    id = fields.IntField(pk=True, description="ID")
    pid = fields.IntField(null=True, description="商品ID")
    pname = fields.CharField(max_length=20, null=True, description="商品名称")
    unit = fields.CharField(max_length=2, null=True, description="单位")
    num = fields.DecimalField(max_digits=10, decimal_places=2, null=True, description="数量")
    availablenum = fields.DecimalField(max_digits=10, decimal_places=2, null=True, description="可用数量")
    spec = fields.CharField(max_length=50, null=True, description="规格")
    price = fields.DecimalField(max_digits=10, decimal_places=4, null=True, description="价格")
    valid_date = fields.DatetimeField(null=True, description="生成日期")
    valid_days = fields.IntField(null=True, description="保质期")
    whid = fields.IntField(null=True, description="仓库ID")
    statu = fields.CharField(max_length=10, null=True, description="状态")
    je = fields.DecimalField(max_digits=10, decimal_places=2, null=True, description="金额")
    remark = fields.CharField(max_length=255, null=True, description="备注")
    del_flag = fields.CharField(max_length=1, default="0", description="删除标志(0代表存在 2代表删除)")
    create_by = fields.CharField(max_length=64, default="", description="创建者")
    create_time = fields.DatetimeField(null=True, description="创建时间")
    update_by = fields.CharField(max_length=64, default="", description="更新者")
    update_time = fields.DatetimeField(null=True, description="更新时间")

    class Meta:
        table = "wms_store"
        table_description = "库存表"

    def __str__(self):
        return f"Store(id={self.id}, pname={self.pname}, num={self.num})"